<%--
  Created by IntelliJ IDEA.
  User: dell
  Date: 2021/7/29
  Time: 15:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link href="static/css/bootstrap.min.css?v=3.3.5" rel="stylesheet">
    <link href="static/css/font-awesome.min.css?v=4.4.0" rel="stylesheet">
    <link href="static/css/animate.min.css" rel="stylesheet">
    <link href="static/css/myAlert.css" rel="stylesheet">
    <link href="static/css/style.min.css?v=4.0.0" rel="stylesheet"><base target="_blank">
    <style type="text/css">
        button{
            float: right;
        }
    </style>
</head>
<body>
<div class="ibox-content MYP" style="margin-left: 5%;margin-top: 5%">
        <h3>项目列表</h3>
        <table class="table table-bordered">
            <thead>
            <tr>
                <th>项目id</th>
                <th>项目名称</th>
                <th>项目编号</th>
                <th>申报单位</th>
                <th>项目类型</th>
                <th>负责人</th>
                <th>状态</th>
            </tr>
            </thead>
            <tbody class="PROJECY">
            </tbody>
        </table>
        第<span id="spanPageNum"></span>页/共<span id="spanTotalPage"></span>页
        <button type="button" class="btn btn-outline btn-primary increase">下一页</button>
        <button type="button" class="btn btn-outline btn-primary reduce">上一页</button>
</div>
<script src="static/js/jquery.min.js?v=2.1.4"></script>
<script src="static/js/bootstrap.min.js?v=3.3.5"></script>
<script src="static/js/plugins/iCheck/icheck.min.js"></script>
<script>
  $(function (){
      $("#spanPageNum").html(1);
      $.ajax({
          url:"findallproject3",
          type:"post",
          data:{page:1},
          success:function (data){
              for (let i = 0; i < data.length; i++) {
                  $(".PROJECY").append(" <tr><td id='pid'>"+data[i].pid+"</td><td>"+data[i].pname+"</td><td>"+data[i].pcode+"</td><td>"+data[i].punit+"</td>" +
                      " <td >"+data[i].pdirector+"</td> <td>"+data[i].ptype+"</td><td>"+data[i].pstate+"</td></tr>")
              }
          }
      })
      //总页数
      $.ajax({
          url:"getPPages",
          method:"post",
          success:function (data){
              pageSize=data;
              $("#spanTotalPage").html(pageSize);
          },
          error:function (){
              window.location.herf="404.jsp"
          }
      })
      //下一页
      $(".increase").click(function (){
          let oldPage=parseInt($("#spanPageNum").text());
          if (oldPage<pageSize){
              let newPage=oldPage+1;
              $("#spanPageNum").html(newPage);
              $.ajax({
                  url:"findallproject3",
                  type:"post",
                  data:{page:newPage},
                  success:function (data){
                      for (let i = 0; i < data.length; i++) {
                          $(".PROJECY").append(" <tr><td id='pid'>"+data[i].pid+"</td><td>"+data[i].pname+"</td><td>"+data[i].pcode+"</td><td>"+data[i].punit+"</td>" +
                              " <td >"+data[i].pdirector+"</td> <td>"+data[i].ptype+"</td><td>"+data[i].pstate+"</td></tr>")
                      }
                  }
              })
          }
      })
      //上一页
      $(".reduce").click(function (){
          let oldPage=parseInt($("#spanPageNum").text());
          if (oldPage>1){
              let newPage=oldPage-1;
              $("#spanPageNum").html(newPage);
              $.ajax({
                  url:"findallproject3",
                  type:"post",
                  data:{page:newPage},
                  success:function (data){
                      for (let i = 0; i < data.length; i++) {
                          $(".PROJECY").append(" <tr><td id='pid'>"+data[i].pid+"</td><td>"+data[i].pname+"</td><td>"+data[i].pcode+"</td><td>"+data[i].punit+"</td>" +
                              " <td >"+data[i].pdirector+"</td> <td>"+data[i].ptype+"</td><td>"+data[i].pstate+"</td></tr>")
                      }
                  }
              })
          }
      })

  })
</script>
</body>
</html>
